Inheritance:-It is a process of showing variables and methods on existing class among new classes. In this process new class acquires variables and methods of existing class.
The class that inherits property is known as child class or sub class or derived class. The class that is inherited (acquires) is called parent class or super class or base class.
Types of inheritance:- It can be following 5 type.
1. Single inheritance
2. Multiple inheritance
3. Multi level inheritance
4. Hierarchical inheritance
5. Hybrid inheritance
1. Single inheritance:- In this type of inheritance parent class has single child and no parent. Similarly child class has single parent and no child.
Class A // Defined class A
{
}
Class B extends A //class B inherit the property of class A
{
}
2. Multiple inheritance:- In this type of inheritance child has multiple parents. Java programming language does not support multiple inheritance but c++ support multiple inheritance.
3. Multi-level inheritance:- In this type of inheritance except root class and leaf class,every class have one child as well as one parent.
Syntax:-
Class A //Defined class A
{
}
Class B extends A //class B inherit the property of class A
{
}
Class C extends B // class C inherit the property of class B
{
}
Class D extends C // class D inherit the property of class C
{
}
4. Hierarchical inheritance:- In this type of inheritance every class have only one parent and multiple child.
Syntax:-
Class A //Defined class A
{
}
Class B extends A //class B inherit the property of class A
{
}
Class C extends B //class C inherit the property of class B
{
}
Class D extends C //class D inherit the property of class C
{
}
Class E extends D //class E inherit the property of class D
{
}
Class F extends E //class F inherit the property of class E
{
}
Class G extends F //class G inherit the property of class F
{
}
Class H extends G //class H inherit the property of class G
{
}
5. Hybrid inheritance:- In this type of inheritance every class have multiple parents and multiple child. Java does not support hybrid inheritance but C# support it.
You can also visit these related articles and blogs-
Leave Comment